package com.hyq.grid.algorithm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by HYQ on 2020/7/27 10:07
 */
public class quadsTodelaunay {
    public quadsTodelaunay(List<Map<String, Double>> points) {

        Points = new ArrayList<>();
        for (int i = 0; i < points.size() - 1; i++) {
            Points.add(new double[]{points.get(i).get("X"), points.get(i).get("Y")});
        }
    }

    private static final double EPSILON = 1.0 / 1048576.0;
    private List<double[]> Points;
    public List<Map> quadsTodel() throws Exception {
        delaunay mydelauny = new delaunay();
        List<Integer> point1 = mydelauny.triangulate(Points);

        List<Map> delatri = new ArrayList<>();
        for (int i = 0; i < point1.size(); ) {
            Map<String, Object> tempMap = new HashMap<String, Object>();
            double[] xout = new double[3];
            double[] yout = new double[3];
            xout[0] = Points.get(point1.get(i))[0];
            xout[1] = Points.get(point1.get(i + 1))[0];
            xout[2] = Points.get(point1.get(i + 2))[0];

            yout[0] = Points.get(point1.get(i))[1];
            yout[1] = Points.get(point1.get(i + 1))[1];
            yout[2] = Points.get(point1.get(i + 2))[1];

            tempMap.put("X", xout);
            tempMap.put("Y", yout);

            delatri.add(tempMap);
            i = i + 3;
        }
        return delatri;
    }
}
